<?php 
/**
 * ... ...
 * ... ...
 *
 */ 


JCAT_Package::ImportClass('JCAT_GtkDialog',JCAT::PACKAGE_MVCGTK) ;
JCAT_Package::ImportInterface('JCAT_IViewForm',JCAT::PACKAGE_MVC) ;


/**
 * 视图类 DBTableLinkDlg 
 *
 * @access public
 */
class DBTableLinkDlg 
	//<<[UnmodifiableBlock.Start]::Extends And Implements::>>//
	extends JCAT_GtkDialog
	implements JCAT_IViewForm
	//<<[UnmodifiableBlock.End]::Extends And Implements::>>// 
{
	
	/**
	 * 构造函数 
	 *
	 * @access	public
	 * @param	$aParent	JCAT_IViewContainer		视图的父对象(父视图 或 控制器)。注意：视图不应单独存在，必须有一个父对象！ 
	 * @return	void
	 */
	public function DBTableLinkDlg(JCAT_IViewContainer $aParent
			,array $arrTables=array()
			,$sLeftTables=''
			,$sRightTables=''
			,$sJoinType='JOIN')
	{
		$this->arrTables = $arrTables ;
		
		// 调用父类构造函数 
		//<<[UnmodifiableBlock.Start]::Call Parent Construct::>>//
		$this->JCAT_GtkDialog('DBTableLinkDlg','template.DBTableLinkView.glade','DlgDBTableLink',$aParent) ;
		//<<[UnmodifiableBlock.End]::Call Parent Construct::>>// 

		$this->Initialize() ;
		
		// 数据整理 左表
		$arrLeftTables = array() ;
		if($sLeftTables)
		{
			$arrTables = explode(',',$sLeftTables) ;
			foreach ($arrTables as $sTableName)
			{
				$arrLeftTables[] = array(trim($sTableName)) ;
			}
		}
		$arrLeftTables[] = array('') ;
		
		// 数据整理 右表
		$arrRightTables = array() ;
		if($sRightTables)
		{
			$arrTables = explode(',',$sRightTables) ;
			foreach ($arrTables as $sTableName)
			{
				$arrRightTables[] = array(trim($sTableName)) ;
			}
		}
		$arrRightTables[] = array('') ;
		
		// 文档
		$aDialogDocument = new JCAT_ArchiveDocument('DBTableLinkDialogDocument') ;
		$aDialogDocument->Set('LeftTables',$arrLeftTables) ;
		$aDialogDocument->Set('RightTables',$arrRightTables) ;
		$aDialogDocument->Set('JoinType',$sJoinType) ;
		$this->SetDocument($aDialogDocument) ;
		
		
		// 
	}
	
	/**
	 * 初始化 视图 
	 *
	 * @access	protected
	 * @return	void
	 */
	protected function Initialize()
	{
		//<<[UnmodifiableBlock.Start]::UICtrl Children::>>//
		// 载入UI控件
		$sCurrentDirectory = dirname(__FILE__).'/' ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.LinkType.php'),'JoinType') ;
		//<<[UnmodifiableBlock.End]::UICtrl Children::>>// 
		
		//<<[UnmodifiableBlock.Start]::View Children::>>//

		//<<[UnmodifiableBlock.End]::View Children::>>// 
		
		
		// 在此加入其它初始化代码 
	 	// TODO ... ...
	 	
		JCAT_Package::ImportClass('TreeTables',$sCurrentDirectory.'Instance.UICtrls/class.TreeTables.php') ;
		$this->AddUICtrl(new TreeTables('TreeLeftTables',JCAT_Language::Sentence('左表'),$this->arrTables),'LeftTables') ;
		$this->AddUICtrl(new TreeTables('TreeRightTables',JCAT_Language::Sentence('右表'),$this->arrTables),'RightTables') ;

	}
	
	/**
	 * 创建主窗体事件 
	 *
	 * @access	protected
	 * @return	void
	 */
	 protected function OnInitView()
	 {
	 	// 数据交换
	 	$this->ExchangeData(JCAT_IViewForm::DOC_TO_UICTRL) ;
	 }


	/**
	 * 对话框 “确定” 按钮事件函数 
	 * 
	 * @access	public
	 * @return	bool
	 */
	public function OnOK() 
	{
		$aMessageQueue = new JCAT_MessageQueue() ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC') ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC_OK') ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC_BAD') ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC_DEBUG') ;

		// 消息输出器
		JCAT_Package::ImportClass('JCAT_MessageGtkDialogPrinter',JCAT::PACKAGE_MSG) ;
		$aMessageQueuePrinter = new JCAT_MessageGtkDialogPrinter($aMessageQueue) ;
		$aMessageQueue->AddPrinter($aMessageQueuePrinter) ;
		
		if( !$this->VerifyData() )
		{
			if( $aMessageQueue->GetMessageCount() )
			{
				$aMessageQueue->PrintQueue() ;
			}
			
			$aMessageQueue->Delete() ;
			return ;
		}
		$aMessageQueue->Delete() ;

		$this->ExchangeData() ;		
		return parent::OnOK() ;
	}


	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetJoinType()
	{
		$aDocument = $this->GetDocument() ;
		return $aDocument->Get('JoinType') ;
	}

	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetTables($sWhere,$bReturnArray=false)
	{
		$aDocument = $this->GetDocument() ;
		$arrRows = $aDocument->Get($sWhere.'Tables') ;
		$arrTables = array() ;
		foreach ($arrRows as $arrOneRow)
		{
			if(empty($arrOneRow[TreeTables::CLM_TABLE]))
			{
				continue ;
			}
			$arrTables[] = $arrOneRow[TreeTables::CLM_TABLE] ;
		}

		if($bReturnArray)
		{
			return $arrTables ;
		}
		else 
		{
			return implode(',',$arrTables) ;
		}
	}
	
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetExpression()
	{
		$aDocument = $this->GetDocument() ;		
		$sExpression = '' ;

		// 左表
		$arrTables = $this->GetTables('Left',true) ;
		if( count($arrTables)>1 )
		{
			$sExpression.= '('.implode(',',$arrTables).')' ;
		}
		else 
		{
			$sExpression.= $arrTables[0] ;
		}
		
		// 连接方式
		$sExpression.= ' '.$aDocument->Get('JoinType').' ' ;
		
		// 右表
		$arrTables = $this->GetTables('Right',true) ;
		if( count($arrTables)>1 )
		{
			$sExpression.= '('.implode(',',$arrTables).')' ;
		}
		else 
		{
			$sExpression.= $arrTables[0] ;
		}
		
		return $sExpression ;
	}
	
	/**
	 * 
	 * 
	 * @access	private
	 * @var		array
	 */
	private $arrTables = array() ;

}

?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取。
 */
/*<<[UnmodifiableBlock.Start]::Coder Dialog Data::>>&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
<<{{DocumentClass:ViewGtkDoc}}>>
eCVEQSU5RFRRbyVEQTAlMTAlN0UlOUYlQjQlMUYlRDElRkMlODAlMjZQJUQyJUFEaVUlODklRDglODElQzUlQUElMTMlOTIlRDglQTYlRUNlSiVDMSVBMiUyNiU4NlQlMjFVJTgwJThBJUZGJUJFcyUwQS0lRDMlQkFpJURBJUMzJUM5JUY2JUY5JUYzJUREd3dfJTkyJTdCJTVEJUVGZSVFRCVGNSUzQyUwQiVFN3VuJTVE
JUU3JURFJTE3cyVFRSU1Q3glOTZQJUIyQSUzQV8lQUYlQTMlN0MlMjklQURrcCUwMiU4QSVBMCUzRSVGQjElQUMlMEIlQUNyJTVEJUNFJThEJUY3JUVCJTJCciU5NCVENyU4Ri0lQzglQjklRjQlMkMlRkIlQjElNUNKJTNCJUQ3UiVEQSVBMyVBQSU1QyVDOGltJTEzJTg5JUYyJURBJTFFJTdEJTFCJUIxJUIyJUQ0JTBG
JUU1JUM2bkMlQ0IlQjUlOEQlQ0ElOTklQUNsJTVDTiU5RiU5N3JVJURCJUQ4JTNGJUQ5JUIyJUZDQSVDQiUzQiVCNSUyQSVFQyVBOUElOUYlOUZ4JUIwJTlFJTlGJTNGJTNEJTNFJTlEMDglQTUlRjklMkIlQjAlRjUlNUV5ViVCOCU3QyVEMiVEMiU4NCU1RSU4NyVFNiVDMSVBMCVBQyU5NiVFRCU5NWd1JThFJTBGeSVD
OCUyNCVBMCVGMlol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